/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller.report;

import com.thienloc.omap.controller.BaseBean;
import com.thienloc.omap.entity.report.ReconcileReport;
import com.thienloc.omap.session.ReconcileReportFacade;
import java.io.Serializable;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@ViewScoped
public class ReconcileBean extends BaseBean implements Serializable {

    @EJB
    private ReconcileReportFacade reconcileReportFacade;
    private final String BY_MONTH = "byMonth";
    private final String BY_DAY = "byDay";
    private Date reconcileDate;
    private String reportTimeType;
    private List<ReconcileReport> list;
    private final Logger logger = LoggerFactory.getLogger(ReconcileBean.class);

    public void getReconcileReport() {
        try {
            String dateFormat = null;
            if (reportTimeType.equals(BY_DAY)) {
                dateFormat = "dd-MM-yyyy";
            } else if (reportTimeType.equals(BY_MONTH)) {
                dateFormat = "MM-yyyy";
            }

            DateFormat df = new SimpleDateFormat(dateFormat);
            String strDate = df.format(reconcileDate);
            list = reconcileReportFacade.getReconcileReport(strDate, dateFormat);
        } catch (Exception ex) {
            logger.error("[{}]: ", getUsername(), ex);
        }
    }

    public List<ReconcileReport> getList() {
        return list;
    }

    public void setList(List<ReconcileReport> list) {
        this.list = list;
    }

    public String getReportTimeType() {
        return reportTimeType;
    }

    public void setReportTimeType(String reportTimeType) {
        this.reportTimeType = reportTimeType;
    }

    public Date getReconcileDate() {
        return reconcileDate;
    }

    public void setReconcileDate(Date reconcileDate) {
        this.reconcileDate = reconcileDate;
    }
}
